#!/bin/sh
#######################################################################
# Begin gpm
#
# Description : Start GPM Console Mouse Service
#
# Author      : DJ Lucas - dj@linuxfromscratch.org
#
# Version     : BLFS 7.0
#
########################################################################

### BEGIN INIT INFO
# Provides:            gpm
# Required-Start:      $local_fs udev
# Should-Start:        $syslog
# Required-Stop:       $local_fs
# Should-Stop:         $syslog
# Default-Start:       2 3 4 5
# Default-Stop:        0 1 6
# Short-Description:   Starts and stops the GPM console mouse service.
# Description:         Starts and stops the GPM console mouse service.
# X-LFS-Provided-By:   BLFS
### END INIT INFO

. /lib/lsb/init-functions

#$LastChangedBy: dj $
#$Date: 2019-10-30 22:22:33 -0500 (Wed, 30 Oct 2019) $

pidfile="/run/gpm.pid"

[ -f /etc/sysconfig/mouse ] && source /etc/sysconfig/mouse

case "${1}" in
   start)
      log_info_msg "Starting GPM console mouse service..."
      if [ "${MDEVICE}" = "" -o "${PROTOCOL}" = "" ]; then
         log_info_msg2 "invalid configuration"
         log_failure_msg
         exit 2
      fi
      start_daemon /usr/sbin/gpm -m "${MDEVICE}" -t "${PROTOCOL}" ${GPMOPTS}
      evaluate_retval
      ;;

   stop)
      log_info_msg "Stopping GPM console mouse service..."
      killproc /usr/sbin/gpm
      evaluate_retval
      ;;

   force-reload)
      # gpm does not honor SIGHUP, restart if running
      kill -0 `pidofproc -p "${pidfile}" /usr/sbin/gpm` 2>/dev/null
      if [ "${?}" = "0" ]; then
         ${0} restart
      else
         log_info_msg "Force reloading GPM console mouse service..."
         log_info_msg2 "not running"
         log_failure_msg
      fi
      ;;

   restart)
      ${0} stop
      sleep 1
      ${0} start
      ;;

   status)
      statusproc /usr/sbin/gpm
      ;;

   *)
      echo "Usage: ${0} {start|stop|force-reload|restart|status}"
      exit 1
      ;;
esac

exit 0

# End /etc/init.d/gpm
